<template>
	<view class="index">
		<view class="item-wrapper">
			<view class="title-wrapper">
				<view class="title">
					供应商名称
				</view>
				<view class="value small">
					{{ form.supplierName.length }}/15
				</view>
				<!-- <uni-icons type="right" color="#ffffff" size="18"></uni-icons> -->
			</view>
			<!-- <view class="tip">
				店铺招牌，公司简称等，与他人不冲突，与店铺有相关性
			</view> -->
			<view class="input-wrapper">
				<input v-model="form.supplierName" type="text" maxlength="15" class="input"
					placeholder="店铺招牌,公司简称等,与他人不冲突,与店铺有相关性" />
			</view>
		</view>
		<view class="item-wrapper">
			<view class="title-wrapper">
				<view class="title">
					主账户
				</view>
				<!-- <view class="value">
					请完善
				</view>
				<uni-icons type="right" color="#898989" size="18"></uni-icons> -->
			</view>
			<view class="form-wrapper">
				<view class="form-item">
					<view class="form-label">
						姓名
					</view>
					<view class="form-value">
						<input v-model="form.manager" type="text" maxlength="5" class="input" placeholder="负责人真实姓名" />
					</view>
				</view>
				<view class="form-item">
					<view class="form-label">
						手机
					</view>
					<view class="form-value">
						<input v-model="form.managerTel" type="number" maxlength="11" class="input"
							placeholder="负责人手机号码" />
					</view>
				</view>
			</view>
		</view>

		<view class="btn" @click="submit">
			开通主账号
		</view>

		<view class="eCode-wrapper">
			<view class="eCode">
				<image class="qrcode" src="../../static/image/supplierECode.png" mode="widthFix"></image>
				<!-- <u-qrcode ref="qrcode" class="qrcode" :size="size" canvas-id="qrcode" :value="uQRCode"></u-qrcode> -->
			</view>
			<view class="tip">
				主账号开通后，请供应商微信扫码二维码，登录供应商小程序，完成入驻资料填写。
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				size: uni.upx2px(400),
				uQRCode: 123213,
				form: {
					manager: '',
					managerTel: '',
					supplierName: '',
					supplyWarehouseId: '',
				}
			}
		},
		mounted() {
			this.form.operationSpecialistName = this.userInfo.nickName;
			this.form.operationSpecialistTel = this.userInfo.phonenumber;
			this.form.operationSpecialistId = this.userInfo.userId;
			this.form.supplyWarehouseId = this.userInfo.supplyWarehouseId;
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			}
		},
		methods: {
			async submit() {
				if (!this.form.supplierName) {
					uni.showToast({
						title: '供应商名称不能为空',
						icon: 'none',
						position: 'bottom'
					})
					return
				}
				if (!this.form.manager) {
					uni.showToast({
						title: '负责人名称不能为空',
						icon: 'none',
						position: 'bottom'
					})
					return
				}
				if (!this.form.managerTel) {
					uni.showToast({
						title: '负责人电话不能为空',
						icon: 'none',
						position: 'bottom'
					})
					return
				}
				const data = await this.$api.post('/adm/supplier', this.form)
				if (data.code === 200) {
					uni.showToast({
						title: '注册成功！',
						icon: 'success',
						position: 'bottom'
					})
					this.form.manager = '';
					this.form.managerTel = '';
					this.form.supplierName = '';
				}
			}
		},
		components: {

		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: auto;

		.item-wrapper {
			background-color: #ffffff;
			margin: 20upx 20upx 0 20upx;
			border-radius: 20upx;
			padding: 25upx;

			&.error {
				box-shadow: 0 0 7upx red;
			}

			.title-wrapper {
				display: flex;
				align-items: center;

				.icon {
					margin-right: 5upx;
				}

				.title {
					height: 34upx;
					line-height: 34upx;
					font-size: 34upx;
					color: #222222;
					padding-left: 10upx;
					border-left: 8upx solid #555BFF;
				}

				.value {
					flex: 1;
					text-align: right;
					font-size: 32upx;
					color: #666666;
				}

				.input {
					flex: 1;
					text-align: right;
					font-size: 32upx;
					color: #666666;
					margin-right: 10upx;
				}
			}

			.input-wrapper {
				padding-top: 15upx;

				.input {
					font-size: 30upx;
					padding: 10upx;
					height: 60rpx;
				}

				.text-area {
					width: 100%;
					font-size: 28upx;
					height: 60upx;
					padding: 10upx;
				}
			}

			.tip {
				font-size: 26upx;
				color: #898989;
			}

			.form-wrapper {
				padding: 0 20upx;

				.form-item {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28upx;
					margin-top: 30upx;

					.form-label {
						color: #232323;
					}

					.form-value {
						color: #666666;

						.input {
							text-align: right;
						}
					}
				}
			}
		}

		.btn {
			margin: 50upx auto;
			width: 400upx;
			height: 80upx;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 10upx;
			color: #ffffff;
			background-color: #555BFF;
			font-size: 28upx;
		}

		.eCode-wrapper {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;

			.eCode {
				padding: 60upx;
				background-color: #ffffff;
				border-radius: 20upx;

				.qrcode {
					width: 500rpx;
					height: 500rpx;
				}
			}

			.tip {
				font-size: 26upx;
				color: #666666;
				width: 600upx;
				margin-top: 50upx;
			}
		}
	}
</style>